<template>
  <el-container class="container layout">
    <el-header class="el-header">
      <a href="/" class="logo">
        原型平台
      </a>
      <div class="bar">
        <div class="buttons-wrap">
          <el-button type="warning" size="small" @click="link('model')">
            新增模块
          </el-button>
          <el-button type="primary" size="small" @click="link('menu')">
            新增菜单
          </el-button>
          <el-button type="success" size="small" @click="link('subMenu')">
            新增功能
          </el-button>
          <el-button type="danger" size="small" @click="link('api')">
            新增接口
          </el-button>
        </div>
        <!-- <el-button type="warning" size="small" @click="link('project')">
          新增项目
        </el-button> -->
      </div>
    </el-header>
    <el-container class="main-container">
      <el-main class="main">
        <div class="container container2">
          <div class="menu-wrap">
            <el-menu background-color="#333" text-color="#fff" active-text-color="#ffd04b" :default-active="defaultActive" @open="handleOpen" @close="handleClose">
              <el-menu-item v-for="(ceil,index) in menuList" :key="ceil.id" :index="ceil.id" @click="menuClick(index)">
                {{ ceil.name }}
              </el-menu-item>
            </el-menu>
          </div>
          <div class="content">
            <nuxt />
          </div>
        </div>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      defaultActive: '1',
      menuList: [{
        id: '1',
        name: '模块管理'
      }, {
        id: '2',
        name: '菜单管理'
      }, {
        id: '3',
        name: '功能管理'
      }, {
        id: '4',
        name: '接口管理'
      }]
    }
  },
  methods: {
    menuClick(index) {
      const { projectId } = this.$route.params
      switch (index) {
        case 0:
          this.$router.push({
            path: `/${projectId}`
          })
          break
        case 1:
          this.$router.push({
            path: `/${projectId}/menuList`
          })
          break
        case 2:
          this.$router.push({
            path: `/${projectId}/subMenuList`
          })
          break
        case 3:
          this.$router.push({
            path: `/${projectId}/apiList`
          })
          break
      }
    },
    link(type, item) {
      const { projectId } = this.$route.params
      if (type === 'menu') {
        this.$router.push({
          path: `/${projectId}/menuDetail`
        })
      } else if (type === 'subMenu') {
        this.$router.push({
          path: `/${projectId}/subMenuDetail`
        })
      } else if (type === 'model') {
        this.$router.push({
          path: `/${projectId}/modelDetail`
        })
      } else if (type === 'moduleEdit') {
        this.$router.push({
          path: `/${projectId}/modelDetail`,
          query: item
        })
      } else if (type === 'api') {
        this.$router.push({
          path: `/${projectId}/apiDetail`,
          query: item
        })
      }
    },
    handleOpen() {

    },
    handleClose() {

    }
  },
  async mounted() {
  /* const projectId = this.$route.params.id
  const res = await this.$axios.get(api.menuList, { params: { projectId } })
  this.menuList = res.data
  this.menuList.forEach(item => {
    item.id = item.id.toString()
  })
  if (this.menuList.length) {
    this.defaultActive = res.data[0].id
  } */
  }
}
</script>

<style lang="scss" scoped>
.container2 {
  display: flex;
  .content {
    padding: 10px;
    flex: 1;
    height: calc(100vh - 60px);
    overflow: auto;
    .wrap {
      display: flex;
      flex-wrap: wrap;
    }
  }
}

.menu-wrap {
  width: 140px;
  height: 100%;
  border-right: 1px solid #ddd;
  /deep/ .el-menu {
    height: 100%;
  }
}
.buttons-wrap{
  padding: 10px 0;
}
</style>
